package com.rk.cmn.listener;
import com.rk.hosp.vo.msm.MsmVo;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

/**
 * @author :Rk.
 * @date : 2022/12/28
 */
public class StreamTest {
    public static void main(String[] args) {
        List<Person> personList = new ArrayList<Person>();
        personList.add(new Person("Tom", 8900, 23, "male", "New York"));
        personList.add(new Person("Jack", 7000, 25, "male", "Washington"));
        personList.add(new Person("Lily", 7800, 21, "female", "Washington"));
        personList.add(new Person("Anni", 8200, 24, "female", "New York"));
        personList.add(new Person("Owen", 9500, 25, "male", "New York"));
        personList.add(new Person("Alisa", 7900, 26, "female", "New York"));

//        List<String> collect = personList.stream().filter(p -> p.getSalary() > 8000).map(Person::getName).collect(Collectors.toList());
//
//        System.out.println(collect);

//        List<String> list = Arrays.asList("adnm", "admmt", "pot", "xbangd", "weoujgsd");
//        Optional<String> max = list.stream().max(Comparator.comparing(String::length));
//        System.out.println(max.get());
//        System.out.println("==========================");

//        List<Integer> list = Arrays.asList(7, 6, 9, 4, 11, 6);
//
//        // 自然排序
//        Optional<Integer> max = list.stream().max(Integer::compareTo);
//        // 自定义排序（从大到小排序） 第二个减去第一个最大的是
//        Optional<Integer> max2 = list.stream().max((o1, o2) -> o2 - o1);
//        System.out.println("自然排序的最大值：" + max.get());
//        System.out.println("自定义排序的最大值：" + max2.get());
//        Optional<Person> max = personList.stream().max(Comparator.comparingInt(Person::getSalary));
//        System.out.println(max.get());
//
//        List<Integer> list = Arrays.asList(7, 6, 4, 8, 2, 11, 9);
//
//        long count = list.stream().filter(x -> x > 6).count();
//        System.out.println(count);
//
//        String[] strArr = { "abcd", "bcdd", "defde", "fTr" };
//        List<String> strList = Arrays.stream(strArr).map(String::toUpperCase).collect(Collectors.toList());
//
//        List<Integer> intList = Arrays.asList(1, 3, 5, 7, 9, 11);
//        List<Integer> intListNew = intList.stream().map(x -> x + 3).collect(Collectors.toList());
//
//        System.out.println("每个元素大写：" + strList);
//        System.out.println("每个元素+3：" + intListNew);


    }
}
